package com.kzw.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kzw.entity.User;
import com.kzw.service.UserService;

@Controller
@RequestMapping("/user")
public class UserAction {

	@Autowired
	private UserService userService;
	
	@RequestMapping("save")
	public String save(User user) {
		userService.save(user);
		System.out.println(user);
		return "redirect:/user/list";		
	}
	
	@RequestMapping("list")
	public String list(Model model) {
		List<User> list = userService.findAll();
		model.addAttribute("list", list);
		return "user_list";
	}
	
	@ResponseBody
	@RequestMapping("list2")
	public List<User> list() {
		List<User> list = userService.findAll();
		return list;
	}
	
	@ResponseBody
	@RequestMapping("list3")
	public List<User> list3() {
		System.out.println("====== list3");
		List<User> list = userService.findByName("张三%", 20);
		return list;
	}
}
